# coding: utf-8
import urllib
import urllib2
import cookielib
from HTMLParser import HTMLParser
import re
import xlrd
import xlwt
import string
from urllib2 import Request, urlopen, URLError, HTTPError
import requests

global COUNT
global TIMEOUT
global pro_dict
global pro_data_dict
global pro_certify_dict

def get_page(url, refer_url, description):
    for i in range(1, COUNT):
        try:
            request = urllib2.Request(url)
            if refer_url:
                request.add_header("Referer", refer_url)
            request.add_header("Host", "www.yfci.gov.cn")
            request.add_header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0")
            response = urllib2.urlopen(request, timeout=TIMEOUT)
            the_page = response.read()
            the_page = the_page.decode('gbk')
            return the_page
        except Exception, x:
            if i == COUNT - 1:
                print description
            else:
                continue

the_page = get_page("http://www.yfci.gov.cn/HousePresell/user_kfs.aspx?key=&kind=&LID=b2fe0e00-f601-4748-9b9e-1475a3ef0085&page=1",None,"shangpingf")
print "=========================="+the_page









